package cdp.tarasenko.epamevospring.controller;

import cdp.tarasenko.epamevospring.model.ChartDataBean;
import cdp.tarasenko.epamevospring.model.CityDataBean;
import cdp.tarasenko.epamevospring.service.ChartsDataService;
import cdp.tarasenko.epamevospring.service.MapDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Some useful texts about Rest, Spring 3 and Json:
 * <ul>
 * <li>
 * <a
 * href="http://www.ibm.com/developerworks/webservices/library/wa-spring3webserv/index.html">Build
 * RESTful web services using Spring 3</a></li>
 * <li>
 * <a href="http://www.javacodegeeks.com/2010/06/spring-3-restful-web-services.html">Spring 3
 * RESTful Web Services</a></li>
 * <li>
 * <a href="http://java.dzone.com/articles/spring-3-rest-json-path-variables">Spring 3 and JSON</a></li>
 * <li>
 * <a href="http://www.mkyong.com/spring-mvc/spring-3-mvc-and-json-example/">Spring 3 MVC and JSON
 * example</a></li>
 * </ul>
 *
 */

/**
 * @author Oleksandr_Tarasenko
 */
@Controller
public class VisualDataController {

    @Autowired
    private ChartsDataService chartsDataService;
    @Autowired
    private MapDataService mapDataService;

    /*
     * "Here, the @RequestBody annotation instructs Spring MVC to map the body of the HTTP request
     * to an Account object. Spring MVC knows to map from JSON because the client set the request
     * Content Type to application/json." See
     * http://blog.springsource.com/2010/01/25/ajax-simplifications-in-spring-3-0/
     */

    @RequestMapping(method = RequestMethod.GET, value = "/emp-grow-data")
    public
    @ResponseBody
    Map<String, Object> getEmployeeGrowingData() {
        return chartsDataService.getEmployeeGrowingData();
    }

    @RequestMapping(method = RequestMethod.GET, value = "/off-grow-data")
    public
    @ResponseBody
    List<ChartDataBean> getOfficesGrowingData() {
        return chartsDataService.getOfficesGrowingData();
    }

    @RequestMapping(method = RequestMethod.GET, value = "/represent-data")
    public
    @ResponseBody
    List<ChartDataBean> getRepresentationData() {
        return chartsDataService.getRepresentationData();
    }

    @RequestMapping(method = RequestMethod.GET, value = "/quarters-number")
    public
    @ResponseBody
    Map<String, Integer> getNumberOfQuarters() {
        Map<String, Integer> result = new HashMap<String, Integer>(1);
        result.put("numOfQuarters", chartsDataService.getNumberOfQuarters());
        return result;
    }

    @RequestMapping(method = RequestMethod.GET, value = "/city-loc", params = "quarter")
    public
    @ResponseBody
    Map<String, Object> getCitiesLocationByQuarter(@RequestParam int quarter) {
        return mapDataService.getCitiesLocationByQuarter(quarter);
    }
}